<?php
/**
 * 会员黑名单
 * @return
 * @author yuncran@126.com
 */

namespace app\model;

use app\BaseModel;
use app\CacheKey;
use app\FieldKey;

class UserBlacklistModel extends BaseModel
{

    /** @var string */
    protected $pk = "id";

    protected $name = "user_blacklist";

    protected $append = ['user'];


    /**
     * @return void
     * @author yuncran@126.com
     */
    public function getUserAttr($value, $data)
    {
        return UserModel::where(['id' => $data['to_user_id']])->field(FieldKey::user_field_has_one)->append(['level_result'])
            ->withAttr('level_result', function ($value, $data) {
                return UserLevelModel::where(['id' => $data['level']])
                    ->field(['id',field('title'),'describe','image','money','expire','color','font_color','background_image','create_time'])
                    ->cache(CacheKey::level_title)->find();
            })->find();
    }

}